package com.shelpe.services.sinbad.controller.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.entity.jpa.Adgroup;
import com.shelpe.services.sinbad.model.RptKeywordDto;

import lombok.Data;

@Data
public class KeywordDto {
	@JsonProperty("keyword_id")
	private long keywordID;
	@JsonProperty("max_mobile_price")
	private int maxMobilePrice;
	@JsonProperty("max_price")
	private int maxPrice;
	@JsonProperty("mobile_is_default_price")
	private Integer mobileIsDefaultPrice;
	@JsonProperty("match_scope")
	private int matchScope;
	@JsonProperty("is_default_price")
	private Integer isDefaultPrice;
	private String word;

	private long adgroupID;
	private long campaignID;

	public void from(RptKeywordDto rptKeyword, Adgroup adgroup) {
		this.campaignID = rptKeyword.getCampaignId() != null ? rptKeyword.getCampaignId() : 0;
		this.adgroupID = rptKeyword.getAdgroupId() != null ? rptKeyword.getAdgroupId() : 0;
		this.keywordID = rptKeyword.getKeywordId() != null ? rptKeyword.getKeywordId() : 0;
		this.word = rptKeyword.getWord() != null ? rptKeyword.getWord() : null;
		this.matchScope = rptKeyword.getMatchscope() != null ? rptKeyword.getMatchscope() : 0;
		this.maxMobilePrice = rptKeyword.getMaxMobilePrice() != null ? rptKeyword.getMaxMobilePrice() : 0;
		this.mobileIsDefaultPrice = rptKeyword.getMobileIsDefaultPrice();
		if (this.mobileIsDefaultPrice == 1) {
			this.maxMobilePrice = this.maxPrice * adgroup.getMobileDiscount() / 100;
		}
		this.maxPrice = rptKeyword.getMaxPrice() != null ? rptKeyword.getMaxPrice() : 0;
		this.isDefaultPrice = rptKeyword.getIsDefaultPrice() ? 1 : 0;
	}
}
